<?php

/*
 * This file is part of the Sylius package.
 *
 * (c) Sylius Sp. z o.o.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Tests\Sylius\Bundle\CoreBundle\CommandDispatcher;

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Sylius\Bundle\CoreBundle\Command\Admin\Account\ResetPassword;
use Sylius\Bundle\CoreBundle\CommandDispatcher\ResetPasswordDispatcher;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\MessageBusInterface;

final class ResetPasswordDispatcherTest extends TestCase
{
    private MessageBusInterface&MockObject $messageBus;

    private ResetPasswordDispatcher $resetPasswordDispatcher;

    protected function setUp(): void
    {
        $this->messageBus = $this->createMock(MessageBusInterface::class);
        $this->resetPasswordDispatcher = new ResetPasswordDispatcher($this->messageBus);
    }

    public function testDispatchesAResetPasswordMessage(): void
    {
        $message = new ResetPassword('token', 'password');

        $this->messageBus
            ->expects($this->once())
            ->method('dispatch')
            ->with($message)
            ->willReturn(new Envelope($message))
        ;

        $this->resetPasswordDispatcher->dispatch('token', 'password');
    }
}
